<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable" :rowSelection="rowSelection">
       <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts" name="csmealsorder-csMealsOrder" setup>
  import {reactive} from 'vue';
  import {BasicTable, TableAction} from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage'
  import {columns, searchApplyForFormSchema} from './CsMealsOrder.data';
  import {list, approveRefund} from './CsMealsOrder.api';
  const queryParam = reactive<any>({});

  //注册table数据
  const { tableContext } = useListPage({
      tableProps:{
           title: '就餐单审批',
           api: list,
           columns,
           canResize:false,
           formConfig: {
              //labelWidth: 120,
              schemas: searchApplyForFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
                 ['diningDay', ['diningDay_begin', 'diningDay_end'], 'YYYY-MM-DD'],
              ],
            },
           actionColumn: {
               width: 120,
               fixed:'right'
            },
            beforeFetch: (params) => {
              params.status=2;
              return Object.assign(params, queryParam);
            },
      }
  })

  const [registerTable, {reload},{ rowSelection }] = tableContext
 

   /**
    * 审核事件
    */
  async function handleApplyFor(record,status) {
      await approveRefund({id: record.id,status:status},handleSuccess);
   }
   
    function handleSuccess() {
       reload();
    }
   /**
      * 操作栏
      */
  function getTableAction(record){
       return [
         {
           label: '审批',
           popConfirm: {
             title: '是否同意',
             confirm: handleApplyFor.bind(null, record,3),
             placement: 'topLeft',
             okText:'同意',
             cancelText:'拒绝',
             cancel:handleApplyFor.bind(null, record,1)
           }
         }
       ]
   }

</script>

<style scoped>

</style>